package rentcar.web;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import rentcar.domain.Car;
import rentcar.service.CarService;

@Controller
@RequestMapping("/car")
public class CarAjaxController {

	@Autowired
	private CarService carService;

	@RequestMapping(value="/info", method= { RequestMethod.POST })
    @ResponseBody
    public Car carInfo(
    		@RequestBody final Car car,
			HttpSession session, Model model) {
		System.out.println("test: " + car.getcarId());
		Car carData = carService.getCarByID(car.getcarId());
		//if (clientData != null) {
		//}
        return carData;
    }
	
	@RequestMapping(value="/delete/{id}/ajax", method= { RequestMethod.POST })
    @ResponseBody
    public Car carDelete(
    		@PathVariable("id") Car car,
			HttpSession session, Model model) {
		
		System.out.println("test: " + car.getcarId());
		carService.deleteCar(car);
		
       return car;
    }
	
	
}
